<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" id="aui-header">
        身份照片
    </header>
    <div class="aui-content">
        <img src="" id="photo" />
    </div>
    <footer class="aui-bar aui-bar-tab aui-border-t" id="footer">
        <div class="aui-bar-tab-item aui-border-r" tapmode id="pic" onclick="picClick();">
            <i class="fa fa-upload"></i>
            <div class="aui-bar-tab-label">
                图片旋转
            </div>
        </div>
        <div class="aui-bar-tab-item" tapmode id="upload_list">
            <i class="fa fa-list"></i>
            <div class="aui-bar-tab-label">
                身份数据上报
            </div>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/util.js"></script>
<script type="text/javascript">
    var r = 90;
    apiready = function() {
        api.parseTapmode();
        $api.fixStatusBar($api.dom('header'));
        tips('请将老人照片转正，否则无法识别。', null, 'div');
        $api.attr($api.byId('photo'), "src", api.pageParam.photo);
        picClick();
        $api.addEvt($api.byId('upload_list'), 'click', function() {
            var pic = $api.attr($api.byId('photo'), "src");
            pic = pic.substring(pic.indexOf(",") + 1);
            //console.log("新图：" + pic);
            saveIdCardInfoCollect(api.pageParam.id, pic);
        });


    };

    function picClick() {
        //r += 90;
        if ($api.attr($api.byId('photo'), "src").indexOf('data')) {
            rotateBase64Img($api.attr($api.byId('photo'), "src"), 360, function(e) {
                //console.log("返回的数据是："+e);
                $api.attr($api.byId('photo'), "src", e);
            });

        } else {
            rotateBase64Img($api.attr($api.byId('photo'), "src"), r, function(e) {
                //console.log("返回的数据是："+e);
                $api.attr($api.byId('photo'), "src", e);
            });
        }
    }

    function saveIdCardInfoCollect(id, photo) {
        api.showProgress({});
        api.ajax({
            url: base + 'gero/api/nurseTerminal/idCardInfoCollect/saveIdCardInfoCollect',
            method: 'post',
            data: {
                values: {
                    "imgBase64": photo,
                    "olderIdCardNumber": id,
                    "olderName": '',
                    "token": $api.getStorage('userinfo').token,
                    "olderNation": '汉'
                }
            }
        }, function(ret, err) {
            if (ret && ret.code == "200") {
                api.alert({
                    msg: '数据上报成功'
                }, function(ret, err) {
                    //coding...
                    console.log(JSON.stringify(ret));
                    var jsfun = 'reashlist();';
                    api.execScript({
                        name: 'browse_oldlist',
                        frameName: 'browser',
                        script: jsfun
                    });

                    api.closeWin({
                        name: 'browse_card_show'
                    });
                    api.closeWin();
                    api.hideProgress();
                });
            } else if (ret && ret.code == 'ERROR') {
                api.alert({
                    msg: ret.msg
                }, function(ret, err) {
                    //coding...
                    console.log(JSON.stringify(ret));

                    api.closeWin({
                        name: 'browse_card_show'
                    });
                    api.closeWin();
                    api.hideProgress();
                });
            } else {
                doLogin();
            }
        });
    }
</script>

</html>
